home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-22 | 4.6 KB | 180 lines | [TEXT/CWIE] |
- /*******************************************************************************\
- | |
- | HToggleRadioButton.cp ©1996-1997 John C. Daub. All rights reserved. |
- | See the file "HToggleRadioButton README" for full details, instructions, |
- | changes, licensing agreement, etc. Due to the important information |
- | included in that file, if you did not receive a copy of it, please contact |
- | the author for a copy. |
- | |
- | John C. Daub <mailto:hsoi@eden.com> |
- | <http://www.eden.com/~hsoi/> <http://www.eden.com/~hsoi/prog.html> |
- | |
- \*******************************************************************************/
-
- #include <LStream.h>
- #include <PP_Messages.h>
- #include <LToggleButton.h>
- #include "HToggleRadioButton.h"
-
- extern const Int32 delay_Animation = 6; // defined in LToggleButton.cp
-
-
- #if ( __PowerPlant__ < 0x01608000 ) // version 1.6/CW11
-
- // ---------------------------------------------------------------------------
- // • CreateFromStream [static, public]
- // ---------------------------------------------------------------------------
- // Used in class registration. Only used if the RegisterClass_() macro is
- // not available (less than PP 1.6)
-
- HToggleRadioButton*
- HToggleRadioButton::CreateFromStream( LStream *inStream )
- {
- return (new HToggleRadioButton(inStream) );
- }
-
- #endif
-
-
- // ---------------------------------------------------------------------------
- // • HToggleRadioButton [public]
- // ---------------------------------------------------------------------------
- // Default constructor
-
- HToggleRadioButton::HToggleRadioButton()
- {
- // nothing
- }
-
-
- // ---------------------------------------------------------------------------
- // • HToggleRadioButton [public]
- // ---------------------------------------------------------------------------
- // Parameterized constructor
-
- HToggleRadioButton::HToggleRadioButton(
- const SPaneInfo &inPaneInfo,
- MessageT inClickedMessage,
- OSType inGraphicsType,
- ResIDT inOnID,
- ResIDT inOnClickID,
- ResIDT inOffID,
- ResIDT inOffClickID,
- ResIDT inTransitionID)
- : LToggleButton( inPaneInfo, inClickedMessage,
- inGraphicsType, inOnID,
- inOnClickID, inOffID,
- inOffClickID, inTransitionID )
- {
- // nothing
- }
-
-
- // ---------------------------------------------------------------------------
- // • HToggleRadioButton [public]
- // ---------------------------------------------------------------------------
- // LStream constructor
-
- HToggleRadioButton::HToggleRadioButton(
- LStream *inStream )
- : LToggleButton( inStream )
- {
- // nothing
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~HToggleRadioButton [public, virtual]
- // ---------------------------------------------------------------------------
- // Destructor
-
- HToggleRadioButton::~HToggleRadioButton()
- {
- // nothing
- }
-
-
- // ---------------------------------------------------------------------------
- // • SetValue [public, virtual]
- // ---------------------------------------------------------------------------
- // Sets the value of the button (on or off)
-
- void
- HToggleRadioButton::SetValue(
- Int32 inValue )
- {
- // set the value of the button clicked on
-
- if ( inValue != mValue ) {
- LControl::SetValue( inValue );
- Refresh();
- }
-
- // and if the button clicked on turned on, have the others
- // turned off
-
- if ( inValue == Button_On ) {
- BroadcastMessage( msg_ControlClicked, (void *)this );
- }
-
- }
-
-
- // ---------------------------------------------------------------------------
- // • HotSpotResult [protected, virtual]
- // ---------------------------------------------------------------------------
- // Action when the button is clicked in. Here is where we animate the
- // the button and prevent the retoggling if clicked in again
-
- void
- HToggleRadioButton::HotSpotResult(
- Int16 inHotSpot )
- {
- // if it's already the same
-
- if ( inHotSpot == mValue ) {
-
- // determine which graphic to draw
-
- ResIDT currentClickState = mOnID;
- if ( mValue == 0 ) {
- currentClickState = mOffID;
- }
-
- // draw it
-
- DrawGraphic( currentClickState );
-
- // broadcast the value message
-
- SetValue( mValue );
-
- // go home
-
- return;
- }
-
- // else it's not the same, so let's animate the button
-
- // Animate Button from current state to a transition state
- // and then to the end state
-
- if (mTransitionID != resID_Undefined) {
-
- FocusDraw();
-
- DrawGraphic(mTransitionID);
- Int32 ticks;
- ::Delay(delay_Animation, &ticks);
-
- ResIDT endClickState = mOnClickID;
- if (mValue != 0) {
- endClickState = mOffClickID;
- }
-
- DrawGraphic(endClickState);
- }
-
- SetValue(1 - GetValue()); // Toggle between on/off
- }
-